package com.axend.aerosense.common.ui;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import androidx.databinding.DataBindingUtil;

import com.axend.aerosense.common.R;
import com.axend.aerosense.common.databinding.CommonCustomFreeVipDialogBinding;

/**
 * Vip免费试用一个月提示弹窗
 */
public class CustomFreeVipDialog extends Dialog{

    private CommonCustomFreeVipDialogBinding databinding;

    public CustomFreeVipDialog(Context context) {
        super(context, R.style.Common_CustomDialog);
        databinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.common_custom_free_vip_dialog, null, false);
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        //设置提示框位置
        WindowManager.LayoutParams lp = window.getAttributes();
        //lp.gravity = Gravity.TOP | Gravity.LEFT;
        lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
        //lp.x = DisplayUtils.dip2px(53);
        //lp.y = DisplayUtils.dip2px(186);
        window.setAttributes(lp);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(databinding.getRoot());
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        initView();
    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        databinding.commonBtnUser.setOnClickListener(v -> {
            onClickBottomListener.onPositiveClick();
        });
    }


    /**
     * 初始化界面控件
     */
    private void initView() {

    }

    /**
     * 获取选择属性值
     * @return
     */
//    public String getSelectValue(){
//        String value = null;
//        try{
//            value = databinding.commonRoomSelectItem.getText().toString().trim();
//        }catch (Exception e){
//
//        }
//        return value;
//    }

    /**
     * 设置确定取消按钮的回调
     */
    public OnClickBottomListener onClickBottomListener;

    public CustomFreeVipDialog setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
        this.onClickBottomListener = onClickBottomListener;
        //初始化界面控件
        initEvent();
        return this;
    }

    public interface OnClickBottomListener {
        /**
         * 点击确定按钮事件
         */
        void onPositiveClick();

    }

}
